home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / New System Software Extensions / Thread Manager Extension 2.0.1 / Compiler Stuff / Interfaces / PInterfaces / Threads.p
Encoding:
Text File  |  1994-06-03  |  5.8 KB  |  193 lines  |  [TEXT/MPS ]

  1. {
  2.     File:        Threads.p
  3.  
  4.     Contains:    External Interface to Thread Manager
  5.  
  6.     Copyright:    © 1991-1994 by Apple Computer, Inc., all rights reserved.
  7.  
  8. }
  9.  
  10. {$IFC UNDEFINED UsingIncludes}
  11. {$SETC UsingIncludes := 0}
  12. {$ENDC}
  13.  
  14. {$IFC NOT UsingIncludes}
  15.     UNIT Threads;
  16.     INTERFACE
  17. {$ENDC}
  18.  
  19. {$IFC UNDEFINED UsingThreads}
  20. {$SETC UsingThreads := 1}
  21.  
  22. {$I+}
  23. {$SETC ThreadsIncludes := UsingIncludes}
  24. {$SETC UsingIncludes := 1}
  25. {$IFC UNDEFINED UsingTypes}
  26. {$I $$Shell(PInterfaces)Types.p}
  27. {$ENDC}
  28. {$IFC UNDEFINED UsingMemory}
  29. {$I $$Shell(PInterfaces)Memory.p}
  30. {$ENDC}
  31. {$SETC UsingIncludes := ThreadsIncludes}
  32.  
  33. {$ENDC}    { UsingThreads }
  34.  
  35. { Thread Gestalt Selectors }
  36. CONST
  37.     gestaltThreadMgrAttr        =        'thds';                { Thread Manager attributes }
  38.     gestaltThreadMgrPresent     =         0;                    { bit true if Thread Mgr is present }
  39.     gestaltSpecificMatchSupport =         1;                    { bit true if Thread Mgr supports exact match creation option }
  40.     gestaltThreadsLibraryPresent =          2;                    { bit true if ThreadsLibrary (Native version) has been loaded }
  41.  
  42.  
  43. { Thread states }
  44. TYPE
  45.     ThreadState = INTEGER;
  46.  
  47. CONST
  48.     kReadyThreadState    = 0;
  49.     kStoppedThreadState    = 1;
  50.     kRunningThreadState    = 2;
  51.  
  52. { Thread environment characteristics }
  53. TYPE
  54.     ThreadTaskRef = Ptr;
  55.  
  56. { Thread characteristics }
  57. TYPE
  58.     ThreadStyle = LONGINT;
  59.  
  60. CONST
  61.     kCooperativeThread    = 1;
  62.     kPreemptiveThread    = 2;
  63.  
  64. { Thread identifiers }
  65. TYPE
  66.     ThreadID = LONGINT;
  67.  
  68. CONST
  69.     kNoThreadID = 0;
  70.     kCurrentThreadID = 1;
  71.     kApplicationThreadID = 2;
  72.  
  73. { Options when creating a thread }
  74. TYPE
  75.     ThreadOptions = LONGINT;
  76.  
  77. CONST
  78.     kNewSuspend = 1;
  79.     kUsePremadeThread = 2;
  80.     kCreateIfNeeded = 4;
  81.     kFPUNotNeeded = 8;
  82.     kExactMatchThread = 16;
  83.  
  84. { Information supplied to the custom scheduler }
  85. TYPE
  86. SchedulerInfoRecPtr    = ^SchedulerInfoRec;
  87. SchedulerInfoRec    = RECORD
  88.     InfoRecSize:                LONGINT;
  89.     CurrentThreadID:            ThreadID;
  90.     SuggestedThreadID:            ThreadID;
  91.     InterruptedCoopThreadID:    ThreadID;
  92.     END;
  93.  
  94. { Routine proc prototypes }
  95. TYPE
  96.     { Prototype for a thread's entry routine }
  97.     ThreadEntryProcPtr = ProcPtr;            { FUNCTION ThreadMain(threadParam: LONGINT): LONGINT; }
  98.  
  99.     { Prototype for a custom scheduler }
  100.     ThreadSchedulerProcPtr = ProcPtr;        { FUNCTION ThreadScheduler(schedulerInfo: SchedulerInfoRec): ThreadID; }
  101.  
  102.     { Prototype for a custom switcher }
  103.     ThreadSwitchProcPtr = ProcPtr;            { PROCEDURE ThreadSwitcher(threadBeingSwitched: ThreadID; switchProcParam: LONGINT); }
  104.  
  105.     { Prototype for a custom termination notification routine}
  106.     ThreadTerminationProcPtr = ProcPtr;        { PROCEDURE ThreadTerminator(threadTerminated: ThreadID; terminationProcParam: LONGINT); }
  107.  
  108.     { Prototypes for debugger new, dispose & schedule thread notification }
  109.     DebuggerNewThreadProcPtr = ProcPtr;            { PROCEDURE DebuggerNewThread(threadCreated: ThreadID); }
  110.     DebuggerDisposeThreadProcPtr = ProcPtr;        { PROCEDURE DebuggerDisposeThread(threadCreated: ThreadID); }   
  111.     DebuggerThreadSchedulerProcPtr = ProcPtr;    { FUNCTION DebuggerThreadScheduler(schedulerInfo: SchedulerInfoRec): ThreadID; }
  112.  
  113.  
  114. { Errors }
  115. CONST
  116.     threadTooManyReqsErr    = -617;
  117.     threadNotFoundErr        = -618;
  118.     threadProtocolErr        = -619;
  119.  
  120.  
  121. { Thread Manager routines }
  122. FUNCTION CreateThreadPool(threadStyle: ThreadStyle; numToCreate: INTEGER; stackSize: Size):OSErr;
  123.     INLINE $303C,$0501,$ABF2;
  124.  
  125. FUNCTION GetFreeThreadCount(threadStyle: ThreadStyle; VAR freeCount: INTEGER):OSErr;
  126.     INLINE $303C,$0402,$ABF2;
  127.  
  128. FUNCTION GetSpecificFreeThreadCount ( threadStyle: ThreadStyle; stackSize: Size; VAR freeCount: INTEGER):OSErr;
  129.     INLINE $303C,$0615,$ABF2;
  130.     
  131. FUNCTION GetDefaultThreadStackSize(threadStyle: ThreadStyle; VAR stackSize: Size):OSErr;
  132.     INLINE $303C,$0413,$ABF2;
  133.  
  134. FUNCTION ThreadCurrentStackSpace(thread: ThreadID; VAR freeStack: LONGINT):OSErr;
  135.     INLINE $303C,$0414,$ABF2;
  136.  
  137. FUNCTION NewThread(threadStyle: ThreadStyle; threadEntry: ThreadEntryProcPtr; threadParam: LONGINT; stackSize: Size; options: ThreadOptions; threadResult: LongIntPtr; VAR threadMade: ThreadID):OSErr;
  138.     INLINE $303C,$0E03,$ABF2;
  139.  
  140. FUNCTION DisposeThread(threadToDump: ThreadID; threadResult: LONGINT; recycleThread: BOOLEAN):OSErr;
  141.     INLINE $303C,$0504,$ABF2;
  142.  
  143. FUNCTION YieldToThread(suggestedThread: ThreadID):OSErr;
  144.     INLINE $303C,$0205,$ABF2;
  145.  
  146. FUNCTION YieldToAnyThread:OSErr;
  147.     INLINE $42A7,$303C,$0205,$ABF2;
  148.  
  149. FUNCTION GetCurrentThread(VAR currentThreadID: ThreadID):OSErr;
  150.     INLINE $303C,$0206,$ABF2;
  151.  
  152. FUNCTION GetThreadState(threadToGet: ThreadID; VAR threadState: ThreadState):OSErr;
  153.     INLINE $303C,$0407,$ABF2;
  154.  
  155. FUNCTION SetThreadState(threadToSet: ThreadID; newState: ThreadState; suggestedThread: ThreadID):OSErr;
  156.     INLINE $303C,$0508,$ABF2;
  157.  
  158. FUNCTION SetThreadStateEndCritical(threadToSet: ThreadID; newState: ThreadState; suggestedThread: ThreadID):OSErr;
  159.     INLINE $303C,$0512,$ABF2;
  160.  
  161. FUNCTION SetThreadScheduler(threadScheduler: ThreadSchedulerProcPtr):OSErr;
  162.     INLINE $303C,$0209,$ABF2;
  163.  
  164. FUNCTION SetThreadSwitcher(thread: ThreadID; threadSwitcher: ThreadSwitchProcPtr; switchProcParam: LONGINT; inOrOut: BOOLEAN):OSErr;
  165.     INLINE $303C,$070A,$ABF2;
  166.  
  167. FUNCTION SetThreadTerminator(thread: ThreadID; threadTerminator: ThreadTerminationProcPtr; terminationProcParam: LONGINT):OSErr;
  168.     INLINE $303C,$0611,$ABF2;
  169.  
  170. FUNCTION ThreadBeginCritical:OSErr;
  171.     INLINE $303C,$000B,$ABF2;
  172.  
  173. FUNCTION ThreadEndCritical:OSErr;
  174.     INLINE $303C,$000C,$ABF2;
  175.  
  176. FUNCTION SetDebuggerNotificationProcs (    notifyNewThread: DebuggerNewThreadProcPtr;
  177.                                         notifyDisposeThread: DebuggerDisposeThreadProcPtr;
  178.                                         notifyThreadScheduler: DebuggerThreadSchedulerProcPtr ):OSErr;
  179.     INLINE $303C,$060D,$ABF2;
  180.  
  181. FUNCTION GetThreadCurrentTaskRef ( VAR threadTRef: ThreadTaskRef ):OSErr;
  182.     INLINE $303C,$020E,$ABF2;
  183.  
  184. FUNCTION GetThreadStateGivenTaskRef ( threadTRef: ThreadTaskRef; threadToGet: ThreadID; VAR threadState: ThreadState ):OSErr;
  185.     INLINE $303C,$060F,$ABF2;
  186.  
  187. FUNCTION SetThreadReadyGivenTaskRef ( threadTRef: ThreadTaskRef; threadToSet: ThreadID ):OSErr;
  188.     INLINE $303C,$0410,$ABF2;
  189.  
  190. {$IFC NOT UsingIncludes}
  191.     END.
  192. {$ENDC}
  193.